import axios from '@/libs/api.request'

// =============== cars/list.vue =========================
export const getTableData = (to_page, per_page, searchData) => {
    return axios.request({
        url: '/api/admin/cars',
        params: {
            page: to_page,
            per_page: per_page,
            search_data: JSON.stringify(searchData)
        },
        method: 'get'
    })
}

export const destroy = (id) => {
    return axios.request({
        url: '/api/admin/cars/' + id,
        method: 'delete'
    })
}

// 查询车架号是否存在
export const existFrameNo = (frame_no) => {
  return axios.request({
    url: 'api/admin/cars/frame_no/' + frame_no,
    method: 'get'
  })
}


// =============== cars/components/add.vue =========================

export const add = (formData) => {
    return axios.request({url: '/api/admin/cars', data: formData, method: 'post'})
}

// =============== cars/components/edit.vue =========================

export const edit = (id, formData) => {
    return axios.request({
        url: '/api/admin/cars/' + id,
        data: formData,
        method: 'patch'
    })
}
export const switchStatus = (formData, id) => {
    return axios.request({
        url: '/api/admin/car_status/' + id,
        data: formData,
        method: 'patch'
    })
}

export const getInfoById = (id) => {
    return axios.request({
        url: 'api/admin/cars/' + id,
        method: 'get'
    })
}
